﻿
Imports System.Data.SqlClient
Imports System.IO
Imports System.Xml
Imports System.Data
Imports Microsoft.Win32
'Imports Microsoft.ReportingServices
Imports Microsoft.Reporting.WinForms

Public Class FrmImpPed

    Private Sub FrmImpPed_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.ReportViewer1.RefreshReport()

        Dim dtcabecera As DataTable
        Dim ds As New dstpedidos
        Dim traercabecera As New SqlDataAdapter
        Dim traerdetalle As New SqlDataAdapter
        Dim dtdetalle As New DataTable

        Try
            '**LEER CABECERA DE LA NOTA*******************************

            Dim param As Integer
            param = 0 'FrmPedidosN.correlativoc
            Dim leerCabecera As New SqlCommand
            leerCabecera.Connection = cn
            leerCabecera.CommandType = CommandType.StoredProcedure
            leerCabecera.CommandText = "Cab_Pedidos"
            leerCabecera.Parameters.AddWithValue("@CodNota", param)
            traercabecera.SelectCommand = leerCabecera

            '**LEER DETALLE DE LA NOTA*******************************

            Dim leerDetalle As New SqlCommand
            leerDetalle.Connection = cn
            leerDetalle.CommandType = CommandType.StoredProcedure
            leerDetalle.CommandText = "Deta_Pedidos"
            leerDetalle.Parameters.AddWithValue("@CodNota", param)
            traerdetalle.SelectCommand = leerDetalle
            cn.Open()
            traercabecera.Fill(ds, "Cab_Pedidos")
            dtcabecera = ds.Tables(0)
            traerdetalle.Fill(ds, "Deta_Pedidos")
            dtdetalle = ds.Tables(1)
            cn.Close()
            '**DESPLEGAR REPORTE*****************************************************************************
            Dim rds1 As Microsoft.Reporting.WinForms.ReportDataSource
            rds1 = New Microsoft.Reporting.WinForms.ReportDataSource("dstcab", dtcabecera)
            Dim rds2 As Microsoft.Reporting.WinForms.ReportDataSource
            rds2 = New Microsoft.Reporting.WinForms.ReportDataSource("dstdet", dtdetalle)
            Me.ReportViewer1.LocalReport.DataSources.Clear()
            Me.ReportViewer1.LocalReport.DataSources.Add(rds1)
            Me.ReportViewer1.LocalReport.DataSources.Add(rds2)
            Me.ReportViewer1.LocalReport.ReportPath = "C:\SistemaRC\SistemaRC\SistemaRC\Reportes\Report1.rdl"
            Me.ReportViewer1.RefreshReport()

        Catch ex As Exception
            Label1.Text = ex.Message
            Label1.Visible = True

        End Try
    End Sub


    Private Sub ReportViewer1_Print(sender As Object, e As Microsoft.Reporting.WinForms.ReportPrintEventArgs) Handles ReportViewer1.Print
        'Me.Close()
        'FrmPedidosN.Focus()
    End Sub


End Class